<?= \common\widgets\Asset::widget(['type'=>['viewer','select2']])?>
<div class="col-sm-12 search-collapse">
    <form id="role-form">
        <div class="select-list">
            <ul>
                <li><?= \common\widgets\FormInput::widget(['name'=>'select|分类','extend'=>['name'=>'where[classify_id]','id'=>'dictType','class'=>'select2','data'=>$this->params['data'],'showvalue'=>'id','showname'=>'name','place'=>'所有分类','value'=>$input['classify_id']??'']])?></li>
                <li><?= \common\widgets\FormInput::widget(['name'=>'input|名称','extend'=>['name'=>'where[name]']])?></li>
                <li><?= \common\widgets\FormInput::widget(['name'=>'select|状态','extend'=>['name'=>'where[status]','value'=>'','place'=>'所有']])?></li>
                <li>
                    <?= $this->render('/iframe',['name'=>'searchbtn|搜索'])?>
                    <?= $this->render('/iframe',['name'=>'resetbtn|重置'])?>
                </li>
            </ul>
        </div>
    </form>
</div>
<div class="col-sm-12 select-table table-striped">
    <table id="bootstrap-table"></table>
</div>

<?php $this->beginBlock('script'); ?>
<script>
    $(function () {
        var options = {
            modalName: "商品",
            sortName:'sort',
            type:0,
            columns: [
                {checkbox: true},
                {field: 'id', title: '商品ID',  sortable: true},
                {field: 'classify', title: '分类'},
                {field: 'name', title: '商品名称'},
                {
                    field: 'main_img',
                    title: '商品主图',
                    formatter: function (value, row, index) {
                        if (!value){
                            return '';
                        }
                        return $.table.imageView(value,null,null,'slide',row.id,'main_img');
                    }
                },
                {
                    field: 'imgs',
                    title: '商品轮播图',
                    formatter: function (value, row, index) {
                        if (!value){
                            return '';
                        }
                        return $.table.imageView(value,null,null,'slide',row.id,'imgs');
                    }
                },
                {field: 'price', title: '标价'},
                {
                    field: 'ac_sales',
                    title: '销量',
                    sortable: true,
                    formatter: function (value, row, index) {
                        var html = '';
                        html += `<div>虚拟销量：${row.vr_sales}</div>`
                        html += `<div>实际销量：${row.ac_sales}</div>`;
                        return `<div>${html}</div>`;
                    }
                },
                {
                    title: '操作时间',
                    field: 'update_time',
                    align: 'center',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return value
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var html = ''
                        html += `<a class="btn btn-info btn-xs" href="javascript:;" onclick="spec(${row.id})">库存管理</a>`
                        return html;
                    }
                }
            ],
            onPostBody:function (data) {
                for (let i = 0; i < data.length; i++) {
                    if(data[i].main_img){
                        new Viewer(document.getElementById('main_imgpts_'+data[i].id),{navbar:false,title:false});
                    }
                    if (data[i].imgs){
                        new Viewer(document.getElementById('imgspts_'+data[i].id),{navbar:false,title:false});
                    }
                }
            }
        };
        $.table.init(options);
    });
    function spec(id) {
        var url = "<?=\yii\helpers\Url::toRoute('spec')?>";
        url=urlcreate(url,'id=' + id);
        $.modal.open("库存管理", url);
    }
</script>
<?php $this->endBlock(); ?>

